第二回実技検定 D - パターンマッチ
提出
WA
code: python
import string
import itertools
import re
s = input()
strings = list(string.ascii_lowercase)
strings_reg = set()
for i in itertools.permutations(strings, 1):
strings_reg.add(i)
for i in itertools.permutations(strings, 2):
strings_reg.add(i)
for i in itertools.permutations(strings, 3):
strings_reg.add(i)
for i in itertools.permutations(strings, 1):
strings_reg.add(('.', *i))
strings_reg.add((*i, '.'))
for i in itertools.permutations(strings, 2):
strings_reg.add(('.', *i))
strings_reg.add((i0, '.', i1)) strings_reg.add((*i, '.'))
ans = 0
for i in strings_reg:
if (re.match("".join(i), s)):
ans += 1
print(ans)
解答
code: python
s = input()
ans_list=[]
for i in range(len(s)):
ans_list.append(".")
for i in range(len(s) - 1):
ans_list.append(target)
ans_list.append(target0 + ".") ans_list.append("." + target1) ans_list.append("..")
for i in range(len(s) -2):
ans_list.append(target)
ans_list.append(target0 + target1 + ".") ans_list.append(target0 + "." + target2) ans_list.append("." + target1 + target2) ans_list.append(target0 + "..") ans_list.append("." + target1 + ".") ans_list.append(".." + target2) ans_list.append("...")
print(len(set(ans_list)))
提出
code: python
import re
import string
import itertools
s = input()
# T = XXX
al = list(string.ascii_lowercase)
al.append('.')
ans = 0
for i in al:
if re.search(i, s):
ans += 1
for i in itertools.product(al, repeat=2):
if re.search("".join(i), s):
ans += 1
for i in itertools.product(al, repeat=3):
if re.search("".join(i), s):
ans += 1
print(ans)